# -*- coding:utf-8 -*-
# created on 2017/3/6
# 

from sympy import Tuple, Interval


def fs_search_multiple(known, poly):  # todo: one key save all values !
    symbols = poly.free_symbols
    answer = []
    for name in known:
        if isinstance(name, (Tuple, tuple)):
            new_name = set(name)
            if new_name & symbols <= new_name:
                values = known[name]
                for value in values:
                    value = list(value)
                    for sym, v in zip(name, value):
                        v_index = value.index(v)
                        if isinstance(v, Interval):
                            value[v_index] = sym
                    symbol_value = dict([(sym, v) for sym, v in zip(name, value)])
                    answer.append(symbol_value)
        else:
            if name in symbols:
                value = list(known[name])[0]
                symbol_value = {name: value}
                answer.append(symbol_value)
    return answer
